import request from "../../utils/request"
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    timer: "",
    minute: 59,
    second: 59,
    modePayment: 0,
    money: 0
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onLoad(option) {
      this.setData({
        money: option.money
      })
      this.setData({
        timer: new Date()
      })
      this.countdown()
    },
    countdown() {
      let m = 1000 * 60
      let h = 60 * m
      var startTime = this.data.timer.getTime()
      let endTime = startTime + h
      let time = setTimeout(() => {
        let differTime = endTime - new Date().getTime()
        let minute = Math.floor(differTime / m)
        let second = Math.floor((differTime - minute * m) / 1000)
        this.setData({
          minute,
          second
        })
        if (differTime <= 0) {
          this.setData({
            minute: 0,
            second: 0
          })

        }
        this.countdown();
      }, 1000)

    },
    confirmPayment() {
      let that = this
      wx.showModal({
        title: '付款详情',
        content: `￥${this.data.money}\r\n支付方式：${this.data.modePayment === 0?"微信":"支付宝"} `,
        showCancel: true,
        confirmColor: "#FF3F3F",
        success(res) {
          if (res.confirm) {
            wx.navigateTo({
              url: `/pages/PaymentSuccess/PaymentSuccess`,
            })
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
    },
    payMentWx() {
      this.setData({
        modePayment: 0
      })
    },
    payMentZfb() {
      this.setData({
        modePayment: 1
      })
    }
  }
})